﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MixingStation
{
    public partial class VideoSetForm : Form
    {
        public VideoSetForm()
        {
            InitializeComponent();
        }

        private void VideoSetForm_Load(object sender, EventArgs e)
        {
            this.chkIsUseVideo.Checked = int.Parse(ConfigurationManager.AppSettings["IsShowVideo"]) == 1 ? true : false;
            this.chkVideoTypeList.SelectedIndex = int.Parse(ConfigurationManager.AppSettings["VideoType"]);
            this.chkIsCapture.Checked = int.Parse(ConfigurationManager.AppSettings["IsCapture"]) == 1 ? true : false;
            this.txtCapturePath.Text = ConfigurationManager.AppSettings["CapturePath"].ToString();

            string ip = ConfigurationManager.AppSettings["LeftVideoIP"].ToString();//读 config 的值
            string port = ConfigurationManager.AppSettings["LeftVideoPort"].ToString();
            string user = ConfigurationManager.AppSettings["LeftVideoUser"].ToString();
            string password = ConfigurationManager.AppSettings["LeftVideoPassword"].ToString();
            string channel = ConfigurationManager.AppSettings["LeftVideoChannel"].ToString();

            txtLeftIp.Text = ip;
            txtLeftPort.Text = port;
            txtLeftUser.Text = user;
            txtLeftPassword.Text = password;
            txtLeftChanel.Text = channel;


            ip = ConfigurationManager.AppSettings["RightVideoIP"].ToString();//读 config 的值
            port = ConfigurationManager.AppSettings["RightVideoPort"].ToString();
            user = ConfigurationManager.AppSettings["RightVideoUser"].ToString();
            password = ConfigurationManager.AppSettings["RightVideoPassword"].ToString();
            channel = ConfigurationManager.AppSettings["RightVideoChannel"].ToString();

            txtRightIP.Text = ip;
            txtRightPort.Text = port;
            txtRightUser.Text = user;
            txtRightPassword.Text = password;
            txtRightChanel.Text = channel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            cfa.AppSettings.Settings["IsShowVideo"].Value = this.chkIsUseVideo.Checked == true ? "1" : "0";
            cfa.AppSettings.Settings["VideoType"].Value = this.chkVideoTypeList.SelectedIndex.ToString();
            cfa.AppSettings.Settings["IsCapture"].Value = this.chkIsCapture.Checked == true ? "1" : "0";
            cfa.AppSettings.Settings["CapturePath"].Value = this.txtCapturePath.Text.Trim();

            cfa.AppSettings.Settings["LeftVideoIP"].Value = this.txtLeftIp.Text .Trim();
            cfa.AppSettings.Settings["LeftVideoPort"].Value = this.txtLeftPort.Text.Trim();
            cfa.AppSettings.Settings["LeftVideoUser"].Value = this.txtLeftUser.Text.Trim();
            cfa.AppSettings.Settings["LeftVideoPassword"].Value = this.txtLeftPassword.Text.Trim();
            cfa.AppSettings.Settings["LeftVideoChannel"].Value = this.txtLeftChanel.Text.Trim();

            cfa.AppSettings.Settings["RightVideoIP"].Value = this.txtRightIP.Text.Trim();
            cfa.AppSettings.Settings["RightVideoPort"].Value = this.txtRightPort.Text.Trim();
            cfa.AppSettings.Settings["RightVideoUser"].Value = this.txtRightUser.Text.Trim();
            cfa.AppSettings.Settings["RightVideoPassword"].Value = this.txtRightPassword.Text.Trim();
            cfa.AppSettings.Settings["RightVideoChannel"].Value = this.txtRightChanel.Text.Trim();

            cfa.Save();
            ConfigurationManager.RefreshSection("appSettings");
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
